package org.liveboardgames.agricola.business.action.overrideaction;

import java.util.Map;

import org.liveboardgames.agricola.business.helper.GameHelper;
import org.liveboardgames.agricola.domain.action.Action;
import org.liveboardgames.agricola.domain.common.Target;
import org.liveboardgames.agricola.domain.farm.Farm;
import org.liveboardgames.agricola.domain.player.Player;
import org.liveboardgames.agricola.model.enums.ResourceTypeEnum;

public class RenovationToClayActionOverride extends ActionOverride {

  public RenovationToClayActionOverride(Action overriddenAction, Target target) {
    super(overriddenAction, target);
  }

  @Override
  public void overrideAction() {
    if (target instanceof Player) {
      Player player = (Player)target;
      Farm farm = player.getFarm();

      // Get the number of rooms of the player's house
      int numberOfRooms = new GameHelper().getNumberOfRooms(farm);

      // Cost is one clay per room and one reed
      Map<String, Integer> cost = overriddenAction.getCost();
      cost.put(ResourceTypeEnum.REED, 1);
      cost.put(ResourceTypeEnum.CLAY, numberOfRooms);
    }
  }

}
